package com.tsingtao.springcloudproject1.controller;

import com.tsingtao.springcloudproject1.feign.Project2FeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
@RestController
@RequestMapping("/config")
@RefreshScope
public class ConfigController {

    @Value(value = "${useLocalCache:false}")
    private boolean useLocalCache;

    @Value(value = "${text:}")
    private String text;

    @Value(value = "${server.port}")
    private String serverPort;

    @Autowired
    private Project2FeignClient project2FeignClient;


    @RequestMapping(value = "/get-use-local-cache", method = GET)
    @ResponseBody
    public boolean getUseLocalCache() {
        return useLocalCache;
    }

    @GetMapping("/get-text")
    public String getText() {
        System.out.println(serverPort + " -> " + text);
        return text;
    }

    @GetMapping("/test-feign")
    public String testFeign() {
        return project2FeignClient.getSelfText();
    }
}
